<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2024/1/29
 * Time: 18:09
 */

namespace app\web\controller;

use app\aliyun\controller\AliyunFilterWord;
use app\api\controller\v2\Auth;
use app\common\cachemodel\AppConfig;
use app\common\cachemodel\Recode;
use app\common\cachemodel\zl7\Zl7AiPredictionActive;
use app\common\lib\Aes;
use app\common\lib\Alidayu;
use app\common\lib\astrolog\Astrolog;
use app\common\lib\astrolog\Forecast;
use app\common\lib\exception\ApiException;
use app\common\lib\IAuth;
use app\common\lib\Util;
use app\common\model\AppTelLogin;
use app\common\model\User;
use think\Cache;
use think\Controller;
use think\Db;
use think\Env;
use think\Exception;
use think\Log;
use think\response\Json;
use XznsTools\curl\Curl;

class AiActive extends Controller
{
    protected $noNeedJudgeSummer = ['香港特别行政区', '澳门特别行政区', '台湾省', '北美洲', '大洋洲', '非洲', '南美洲', '欧洲', '亚洲', ''];

    protected $questionLimit = 20;


    protected $setting = [
        'natal' => [
            'planet' => [
                [1, 8.5], [1, 7.5], [1, 3.5], [1, 3.5], [1, 4], [1, 4.5], [1, 4.5], [1, 2.5], [1, 2.5], [1, 2.5],
                [0, 0], [0, 0], [0, 0], [0, 0], [1, 2.5], [0, 0], [0, 0], [1, 2.5], [1, 2.5], [1, 2.5], [1, 2.5]
            ],
            'phase' => [
                0 => [1, 0], 60 => [1, 0], 90 => [1, 0], 120 => [1, 0], 180 => [1, 0],
                45 => [0, 0], 135 => [0, 0], 30 => [0, 0], 150 => [0, 0], 72 => [0, 0], 144 => [0, 0]
            ],
            'arabic' => [
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]
            ],
            'h_sys' => 'p',
            'firdaria' => 'default',
            'bound_type' => 'default',
            'ecliptic' => 0,
            'profection_push_direction' => 0,
            'decanates' => 0,
            'ayanamsa' => 0,
            'location_use' => 0
        ],
    ];

    public function _initialize()
    {
        parent::_initialize();
        $param = $this->request->param();
        $app_type = $param['app-type'] ?? 'web';
        $version = $param['version'] ?? '';
        $this->assign(['app_type' => $app_type, 'version' => $version]);
        $this->assign('oss', Env::get('host.photo'));
        $this->assign('domain', Env::get('host.domain'));
    }

    /**
     * 获取手机验证码
     * @return Json
     * @throws \Exception
     */
    public function getCode()
    {
        $tel = input('tel/s', '');// 账号注销时，手机号为空
        $areaCode = input('area_code/d', 86);

        // 检查手机号是否正确
        if (!$tel || !Util::telRuleCheck($tel, $areaCode))
        {
            return show(config('code.error'), '手机号错误');
        }
        /**
         * 过滤非法获取验证码请求，直接返回发送成功
         */
        if (Util::isIllegalRequest(true))
        {
            return show(config('code.success'), '发送成功');
        }

        $telStr = 'isSend:' . $areaCode . '-' . $tel;
        $isSendCode = Cache::get($telStr, false);
        if ($isSendCode)
        {
            return show(config('code.error'), '操作频繁，请稍后再试～');
        }

        $time = time();// 当前时间  有效时间暂定为十分钟 600s

        $expire = 600;

        $ip = $this->request->ip();

        try
        {
            $data = (new AppTelLogin())->where(['tel' => $tel, 'expire_time' => ['>', $time]])->findOrFail()->toArray();
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        // 十分钟内无已有验证码
        if (empty($data))
        {
            $code = random_int(100000, 999999);// 六位验证码

            $expire_time = $time + $expire;
            try
            {
                Db::table('app_tel_login')->insertGetId([
                    'tel' => (string)$tel,
                    'create_time' => $time,
                    'expire_time' => $expire_time,
                    'code' => $code,
                ]);
            }
            catch (\Exception $e)
            {
                Log::write('获取手机验证码失败：' . $e->getMessage() . PHP_EOL . '失败行数：' . $e->getLine() . PHP_EOL . '错误文件：【' . $e->getFile() . '】');
                return show(config('code.error'), '发送失败');
            }

        } else
        {
            $code = $data['code'];
        }
        $alidayu = (new AppConfig())->configInfo('alidayu');
        // 短信模板ID 配置KEY
        // 登录或绑定
        $smsIdConfigKey = $areaCode === 86 ? 'login_code' : 'abroad_login_code';
        if ((int)$areaCode === 1)
        {
            $result = Alidayu::getInstance()->sendSmsUSA($tel, $code, $smsIdConfigKey);
        } else
        {
            $result = Alidayu::getInstance()->sendSms($tel, $code, $alidayu[$smsIdConfigKey], $areaCode);
        }
        if (!$result)
        {
            return show(config('code.error'), '发送失败');
        }
        Cache::set($telStr, true, 50);
        // 记录短信日志
        model('log')->save([
            'tel' => (string)$tel,
            'ip' => $ip,
            'create_time' => $time,
            'type' => 1,
        ]);
        return show(config('code.success'), '发送成功');
    }

    /**
     * @title 手机验证码登录
     * @method POST
     * @return Json
     * @throws ApiException
     */
    public function mobile()
    {
        $tel = input('tel/s', '');
        if (Util::CheckAppVersion('2.6.0') !== '小')
        {
            $tel = (new Aes())->decryptWithOpenssl($tel);
        }
        $code = input('code/s', '');
        $areaCode = input('area_code/d', 86);
        $time = $this->request->time();
        $ip = $this->request->ip();
        $appConfig = config('app');

        // 手机号不可注册
        $checkInfo = $this->CheckUserTel($tel, $areaCode);
        $user = $checkInfo['user'];
        if ($checkInfo['msg'])
        {
            return show(config('code.error'), $checkInfo['msg']);
        }
        // 短信验证码 或 密码是否存在
        if (empty($code))
        {
            return show(config('code.error'), '手机短信验证码');
        }
        // 短信登录时，检测验证码是否正确
        if (!empty($code))
        {
            if (!in_array($tel, $appConfig['mobile'])
                || ($areaCode === 86 && $code != substr($appConfig['code'] * (substr($tel, 3, 6)), 0, 6)))
            {
                //苹果和安卓应用商店审核账号，固定验证码为666666
                if (($tel == '13045794520' && $code == '666666')
                    || ($tel == '13261877781' && $code == '666666'))
                {

                } else
                {
                    //  validate 严格校验
                    $mobileCode = Alidayu::getInstance()->checkSmsIdentify($tel, $areaCode);

                    if ($code != $mobileCode)
                    {
                        return show(config('code.error'), '短信验证码错误');
                    }
                }
            }
        }
        // 生成token  和 token到期时间
        $token = IAuth::setAppLoginToken($tel);
        $data = [
            'token' => $token,
            'token_expire' => strtotime("+" . $appConfig['login_time_out_day'] . " days"),
        ];
        $UserModel = new User();
        //判断用户是否绑定准了号
        if ($user)
        {
            $UserModel->check_uen($user);
        }

        $nickname = preg_replace('/(1[3456789]{1}[0-9])[0-9]{4}([0-9]{4})/i', '$1****$2', $tel);
        $isRegist = false;
        // 该用户是否正常  forbidden==1 禁止登录
        if ($user && $user['forbidden'] == 0)
        {
            // 已过期重新生成access_token
            if ($time > $user['token_expire'] || !in_array($tel, $appConfig['mobile']))
            {
                $mobileTel = $areaCode === 86 ? $tel : $areaCode . '-' . $tel;
                $UserModel->save($data, ['tel' => $mobileTel]);
            } else
            {
                $token = $user['token'];
            }
            if (!$user['nickname'])
            {
                try
                {
                    Db::table('app_user')->where('tel', $tel)
                        ->update(['nickname' => $nickname]);
                }
                catch (Exception $e)
                {
                    Log::write('手机验证码登陆时初始化用户昵称失败' . $e->getMessage(), true);
                }
            }
        } elseif ($user && $user['forbidden'] == 1)
        {
            return show(config('code.error'), '该账号禁止登录');
        } //手机号不可注册
        elseif (!$user && !empty($code) && !empty($tel))
        {
            $checkResult = Util::registCheckLogoutCD(['tel' => $tel]);
            if (!$checkResult['result'])
            {
                return show(config('code.error'), $checkResult['msg']);
            }
            // 第一次登录 注册数据
            $user['uen'] = substr(md5($this->request->time(true) . mt_rand(0, 1000000) . uniqid('', false)), 0, 12);
            $user['nickname'] = $nickname;
            $user['reg_time'] = $time;
            $user['reg_ip'] = $ip;
            $user['last_login'] = $time;
            $user['last_ip'] = $ip;
            $user['last_active'] = $time;
            $user['status'] = 1;
            $user['sex'] = 1;
            $user['tel'] = $areaCode === 86 ? $tel : $areaCode . '-' . $tel; // 国内手机号不拼接国际手机区号
            $user['is_first_login'] = 1;
            $user['uc_id'] = md5($tel . $this->request->time(true));
            $user['token'] = $data['token'];
            $user['token_expire'] = $data['token_expire'];
            $user['has_self_recode'] = 0;
            $user['channel'] = Util::getChannelId();
            try
            {
                $user['id'] = $UserModel->insertGetId($user);
            }
            catch (\Exception $e)
            {
                return show(config('code.error'), '注册失败,请稍后重试');
            }
        }

        if ($user)
        {
            $result = [
                'has_self_recode' => $user['has_self_recode'],
                'user_access_token' => (new Aes())->encryptWithOpenssl($token . "||" . $user['id']),
            ];
            return show(config('code.success'), 'ok', $result);
        }
        return show(config('code.error'), '登录失败');
    }

    /**
     * 检测手机号格式，不可注册
     * @param $tel
     * @param int $areaCode 手机区号
     * @return array
     * @throws ApiException
     */
    public function CheckUserTel($tel, $areaCode = 86)
    {
        // 手机号是否存在
        if (!Util::telRuleCheck($tel, $areaCode))
        {
            Log::write($areaCode . $tel . '手机号错误', 'error');
            $msg = '手机号错误';
        }
        //判断手机号是否注册过
        try
        {
            $tel = $areaCode === 86 ? $tel : $areaCode . '-' . $tel;

            $user = (new \app\common\cachemodel\User())
                ->field('id,forbidden,has_self_recode,password,young_pwd,nickname,uc_id,avatar,token_expire,token,uen,is_login_record')
                ->where(['tel' => $tel])->findOrFail()->toArray();
        }
        catch (Exception $e)
        {
            $user = [];
        }
        return ['user' => $user, 'msg' => $msg ?? ''];
    }

    /**
     * 提问列表
     * @return Json
     * @throws \Exception
     */
    public function questionList()
    {
        $data = Db::table('wechat_backup_07_18_14_43_00.zhunle_virtual_user_name')->limit(8)->column('name');
        $question = [
            '赐我一个男友',
            '升职加薪',
            '顺利上岸',
            '暴富暴瘦',
            '和前男友复合',
            '前单位倒闭',
            '顺利考过驾照',
            '身体恢复健康'
        ];
        $d = [];
        foreach ($data as $key => $name)
        {
            $d[] = [
                'name' => $name,
                'question' => $question[$key],
                'percent' => random_int(30, 96)
            ];
        }
        return show(config('code.success'), 'success', $d);
    }

    /**
     * 判断用户是否登录和运行环境
     * @return array|Json
     */
    private function uidAndRecode()
    {
        $headers = $this->request->header();
        $app = true;
        if (isset($headers['app-type']) && in_array($headers['app-type'], ['android', 'ios'], true))
        {
            //校验token
            $auth = new Auth();
            $uid = $auth->user['id'];
        } else
        {
            $app = false;
            $token = $headers['user-access-token'] ?? '';//是否已登录
            $token = openssl_decrypt(base64_decode($token), 'AES-128-CBC', 'aiVjKg65lvKaYBuN', OPENSSL_RAW_DATA, 'EPzH5lnC5a47QEYo');
            $uid = explode('||', $token)[1] ?? 0;

        }
        return [
            'app' => $app,//true=>app内打开
            'uid' => $uid,
        ];
    }

    /**
     * AI首页
     * @return mixed
     * @throws ApiException
     */
    public function aiAnswer2024()
    {
        $height = input('h/d', 0);
        $isShowNav = input('zhunle_not_show_nav/d', 0);
        $header = request()->header();
        if (isset($header['app-type']) && in_array($header['app-type'], ['android', 'ios'], true))
        {
            $app = true;
        } else
        {
            $app = false;
        }
        $id = input('id/d', 0);
        if ($id)
        {
            $data = (new Zl7AiPredictionActive())->getInfoById($id);
            $uid = $data['uid'];
        } else
        {
            $userInfo = $this->uidAndRecode();
            $data = (new Zl7AiPredictionActive())->getUserLastQuestion($userInfo['uid']);
            $id = $data['id'] ?? 0;
            $uid = $userInfo['uid'];
        }
        $user = current((new User())->batchGetUserInfo([$uid]));
        $nickname = $user['nickname'] ?? '';
        $header = $this->getHeader($header);
        return $this->fetch('aiAnswer2024',
            [
                'nickname' => $nickname ?? '',
                'header' => json_encode($header, JSON_UNESCAPED_UNICODE),
                'id' => $id,
                'app' => $app,
                'question_limit' => $this->questionLimit,
                'height' => $height,
                'is_show_nav' => 1
            ]);
    }

    /**
     * 问题详情
     * @return Json
     * @throws ApiException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function questionDetail()
    {
        $userInfo = $this->uidAndRecode();
        if (!$userInfo['uid'])
        {
            return show(405, '请登录');
        }
        $zl7AiPredictionActiveModel = new Zl7AiPredictionActive();
        if ($userInfo['app'])
        {
            $data = $zl7AiPredictionActiveModel->getUserLastQuestion($userInfo['uid']);
            $id = $data['id'] ?? 0;
            $question = $data['question'] ?? '';
            $assistUid = $data['assist_uid'] ?? 0;
            $assistedUid = $data['uid'] ?? 0;
            $answer = $data['content'] ?? '';
            $percent = $data['percent'] ?? 0;
        } else
        {
            $id = input('id/d', 0);
            $data = $zl7AiPredictionActiveModel->getUserLastQuestion($userInfo['uid']);
            if ($id)
            {
                $data2 = $zl7AiPredictionActiveModel->getInfoById($id);
                $assistUid = $data2['assist_uid'] ?? 0;
                $assistedUid = $data2['uid'] ?? 0;
            } else
            {
                $assistedUid = $userInfo['uid'];
//                $assistUid = 0;
                // 当没有获取到ID时，先获取上一次的记录
                $assistUid = (int)($data['assist_uid'] ?? 0); // 助力人uid
            }
            $question = $data['question'] ?? '';
            $answer = $data['content'] ?? '';
            $percent = $data['percent'] ?? 0;
        }
        $rid = (new Recode())->getRecodeLists($userInfo['uid'], 1)['id'] ?? 0;
        if (!$rid)
        {
            return show(406, '添加档案');
        }
        return show(config('code.success'), 'success', [
            'id' => $id,
            'rid' => $rid,
            'question' => $question,
            'answer' => $answer, // 控制是否显示答案
            'percent' => $percent,
            'assist_uid' => $assistUid, //助力人uid 控制助力弹窗
            'assisted_uid' => $assistedUid,// 被助力用户uid
            'uid' => $userInfo['uid'],// 当前用户uid
            'app' => $userInfo['app']

//            'id' => $id,
//            'nickname' => '被助力人的昵称',//被助力人的昵称
//            'question' => 'fdf',
//            'answer' => '辅导时间多少分建设大街啊哈飞机大厦合法发多少尽快回复金黄色的立法会', // 控制是否显示答案
//            'percent' => 0,
//            'assist_uid' => 0, // 助力人,控制助力弹窗
//            'uid' => 1,
//            'app' => 0
        ]);
    }

    /**
     * 助力
     * @return Json
     * @throws \Exception
     */
    public function assist()
    {
        $userInfo = $this->uidAndRecode();
        if (!$userInfo['uid'])
        {
            return show(405, '请登录');
        }
        $id = input('id/d', 0);
        $zl7AiPredictionActiveModel = new Zl7AiPredictionActive();
        $info = $zl7AiPredictionActiveModel->getInfoById($id);
        if (!$info)
        {
            return show(config('code.error'), '请求异常');
        }
        if ($info['uid'] == $userInfo['uid'])
        {
            return show(config('code.error'), '不可助力自己');
        }
        if ($info['assist_uid'])
        {
            return show(config('code.success'), '助力失败', ['message' => '用户已完成2024好事预测，你也来试试吧~']);
        }
        $info2 = $zl7AiPredictionActiveModel->where('assist_uid', $userInfo['uid'])->find();
        if ($info2)
        {
            return show(config('code.success'), '助力成功', ['message' => '你已经助力过其他伙伴，只可助力1次']);
        }
        $data = [
            'uid' => $info['uid'],
            'assist_uid' => $userInfo['uid'],
            'update_time' => time()
        ];
        $zl7AiPredictionActiveModel->updateData($id, $data);
        return show(config('code.success'), '助力成功', ['message' => '']);
    }

    /**
     * 提问
     * @return Json
     * @throws \Exception
     */
    public function askQuestion()
    {
        $question = trim(input('question/s', ''));
        if (!$question)
        {
            return show(config('code.error'), '请填写问题');
        }
        if (mb_strlen($question) > $this->questionLimit)
        {
            return show(config('code.error'), '问题最多20字');
        }
        $res = AliyunFilterWord::checkText($question, 'ai_forecast');
        //若内容有违规且超过配置的相似比例，则进行隐藏不显示，将标签存入库中
        if ($res)
        {
            return show(0, '你输入的问题不合适，换个试试吧');
        }
        $userInfo = $this->uidAndRecode();
        if (!$userInfo['uid'])
        {
            return show(405, '请登录');
        }
        $rid = (new Recode())->getRecodeLists($userInfo['uid'], 1)['id'] ?? 0;
        if (!$rid)
        {
            return show(406, '添加档案');
        }
        $recordInfo = (new Recode())->getInfoById($rid);

        // 获取问题分类信息
        $url1 = Env::get('haozhungpt.url') . '/api/get_question_category';
        $pythonRes1 = Curl::request($url1, [
            'uid' => $userInfo['uid'], 'query' => $question
        ], 'post', ['Content-Type' => 'application/json'], 'json');
        $content = '';
        $percent = 0;
        if ($pythonRes1['success'] && isset($pythonRes1['data']) && !empty($pythonRes1['data']))
        {
            // 问题中包含
            $categorys = array_column($pythonRes1['data'], 'category');
            if (in_array(13, $categorys, true))
            {
                return show(config('code.error'), '你输入的问题不合适，换个试试吧');
            }
            try
            {
                $percent = (new Forecast())->init($recordInfo, $pythonRes1['data']);
            }
            catch (\Exception $e)
            {
                $percent = 55;
                Log::write('AI预测失败：' . $e->getMessage() . '【' . $e->getFile() . $e->getLine() . '】', 'error');
            }
            // 根据问题和概率 获取词条
            $url2 = Env::get('haozhungpt.url') . '/api/get_annual_forecast/';
            $pythonRes2 = Curl::request($url2, [
                'uid' => $userInfo['uid'], 'query' => $question, 'percent' => $percent . '%'
            ], 'post', ['Content-Type' => 'application/json'], 'json');
            if ($pythonRes2['success'] && isset($pythonRes2['data']) && $pythonRes2['data'])
            {
                $content = $pythonRes2['data'];
            }
        }

        $data = [
            'uid' => (int)$userInfo['uid'],
            'question' => $question,
            'content' => $content,
            'percent' => $percent,
            'create_time' => time(),
            'extend' => json_encode($pythonRes1['data'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
        ];
        $id = (new Zl7AiPredictionActive())->saveData($userInfo['uid'], $data);
        if ($id)
        {
            return show(config('code.success'), '提问成功', ['id' => $id, 'answer' => $content]);
        }
        return show(config('code.error'), '提问失败');
    }

    /**
     * 添加档案页面
     * @return mixed
     */
    public function addRecode()
    {
        $aiId = input('ai_id/d', 0);
        $data = [
            'oss' => Env::get('host.photo'),
        ];

        $data['title'] = '添加档案';
        // 设置档案默认值
        $data['record'] = [
            'name' => '游客' . date('hms'),
            'comments' => '亲友',
            'avatar' => Env::get('host.domain') . '/static/synastry/img/avatar-default.png',
            'type' => 2,
            'year' => 1995,
            'month' => '01',
            'day' => '01',
            'hour' => '00',
            'minute' => '00',
            'timezone' => 8,
            'birth_country' => '北京市',
            'birth_province' => '北京市',
            'birth_city' => '东城区',
            'live_country' => '北京市',
            'live_province' => '北京市',
            'live_city' => '东城区',
            'isself' => 0,
            'long_deg' => 116,
            'long_min' => 25,
            'ew' => 1,
            'lat_deg' => 39,
            'lat_min' => 55,
            'ns' => 1,
            'is_summer' => 0,
        ];
        $header = request()->header();
        $header = $this->getHeader($header);
        $data['header'] = json_encode($header, JSON_UNESCAPED_UNICODE);
        $data['ai_id'] = $aiId;
        return $this->fetch('addRecode', $data);

    }

    /**
     * 保存档案
     * @return Json
     * @throws ApiException
     */
    public function saveRecode()
    {
        $userInfo = $this->uidAndRecode();
        if (!$userInfo['uid'])
        {
            return show(config('code.success'), '请登录');
        }
        $rid = (new Recode())->getRecodeLists($userInfo['uid'], 1)['id'] ?? 0;
        if ($rid)
        {
            return show(0, '已有档案');
        }
        $param = request()->param();
        $time = time();
        $is_summer = 0;
        $name = str_replace(["\r\n", "\r", "\n"], "", $param['name']);
        // 只判断大陆地区的夏令时
        if (!in_array($param['birth_country'], $this->noNeedJudgeSummer, true))
        {
            $is_summer = isSummerTime($param['hour'], $param['minute'], 0, $param['month'], $param['day'], $param['year']) ? 1 : 0;// 是否开启夏令时
        }
        // 设置档案默认值
        $data = [
            'uid' => $userInfo['uid'],
            'name' => $name,
            'comments' => $param['comments'],
            'avatar' => Env::get('host.domain') . '/static/synastry/img/avatar-default.png',
            'type' => $param['sex'],
            'year' => $param['year'],
            'month' => (int)$param['month'],
            'day' => (int)$param['day'],
            'hour' => (int)$param['hour'],
            'minute' => (int)$param['minute'],
            'timezone' => 8,
            'birth_country' => $param['birth_country'],
            'birth_province' => $param['birth_province'],
            'birth_city' => $param['birth_city'],
            'live_country' => $param['live_country'],
            'live_province' => $param['live_province'],
            'live_city' => $param['live_city'],
            'isself' => 1,
            'long_deg' => (int)$param['long_deg'],
            'long_min' => (int)$param['long_min'],
            'ew' => (int)$param['ew'],
            'lat_deg' => (int)$param['lat_deg'],
            'lat_min' => (int)$param['lat_min'],
            'ns' => (int)$param['ns'],
            'is_summer' => $is_summer ? 1 : 0,
        ];
        $validate = validate('Recode');

        if (!$validate->scene('add')->check($data))
        {
            return show(config('code.error'), (string)$validate->getError());
        }
        $rid = (new Recode())->SaveData($userInfo['uid'], $data);
        if (!$rid)
        {
            return show(config('code.error'), '添加失败');
        }

        if ($data['comments'] === '自己' && $data['isself'] === 1)
        {
            //删除用户缓存
            (new User())->updateUserinfo(['id' => $userInfo['uid']], ['nickname' => $data['name'], 'username' => $data['name'], 'avatar' => $data['avatar'], 'has_self_recode' => 1]);
        }
        // 查询当前星盘日月水金火木土等星落座落宫存入数据库
        $astro_data = Astrolog::getInstance()->setExecPrefix(config('astrolog.prefix'))
            ->setIsAstrolabe(false)
            ->setRecode1($data)
            ->setUserSetting($this->setting)
            ->getTheRecodeAstro();
        $astro_data['rid'] = $rid;
        $astro_data['create_time'] = $time;
        Db::table('app_recode_info')->insertGetId(['rid' => $rid, 'create_time' => $time, 'last_time' => $time]);// 新增当前档案访问数据
        $aid = Db::table('app_recode_astro')->insertGetId($astro_data);// 新增当前档案行星数据
        (new Recode())->UpdateData($userInfo['uid'], $rid, ['aid' => $aid]);
        return show(config('code.success'), '添加成功');
    }

    /**
     * @param $header
     * @return mixed
     */
    protected function getHeader($header)
    {
        unset($header['accept-encoding'], $header['sec-fetch-dest'], $header['sec-fetch-user'], $header['ec-fetch-mode'], $header['sec-fetch-site'], $header['user-agent'], $header['dnt'], $header['connection'], $header['host'], $header['content-length'], $header['cookie'], $header['sec-fetch-mode'], $header['sec-ch-ua-platform'], $header['sec-ch-ua'], $header['sec-ch-ua-mobile']);
        return $header;
    }
}
